package wibrst.utils{
	import flash.geom.Point;
	import wibrst.geom.BlockNode;
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class MathUtil {
		
		static public function getRdmNum( iBase:int, iLen:int ):int {
			return iBase + Math.random() * iLen;
		}
		
		static public function getMaxMinFixed( nMax:Number, nMin:Number, nOrig:Number ):Number {
			if( nOrig < nMin ) return nMin;
			else if( nOrig > nMax ) return nMax;
			else return nOrig;
		}
		
		static public function getModPositive( num:Number, base:Number ):Number {
			var nRes:Number = num % base;
			if ( nRes < 0 ) nRes += base;
			return nRes;
		}
		
		static public function roundEven( nOrig:Number ):Number {
			return Math.floor(nOrig) % 2 == 0?Math.floor(nOrig): Math.ceil(nOrig)%2==0? Math.ceil(nOrig): nOrig+1;
		}
		
		static public function radiansToDegrees(radians:Number):int{
			return radians * 180 / Math.PI;
		}
		
		static public function degreesToRadians(degrees:Number):Number{
			return degrees * Math.PI / 180;
		}
		
		static public function getDistOf2Point( p1:Point, p2:Point):Number {
			return Math.sqrt( Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2) );
		}
		
		static public function getDistOf2BlockNode( bn1:BlockNode, bn2:BlockNode ):Number {
			return Math.sqrt( Math.pow(bn1.c - bn2.c, 2) + Math.pow(bn1.r - bn2.r, 2) );
		}
	}

}